package com.limingfeiyu.platform.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.limingfeiyu.common.web.PageTable;
import com.limingfeiyu.platform.management.entity.HospitalItem;
import com.limingfeiyu.platform.management.mapper.HospitalItemMapper;
import com.limingfeiyu.platform.management.service.IHospitalItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 医院_项目 服务实现类
 * </p>
 *
 * @author 黎铭飞羽
 * @since 2024-04-12
 */
@Service
public class HospitalItemServiceImpl extends ServiceImpl<HospitalItemMapper, HospitalItem> implements IHospitalItemService {

    @Override
    public Page<HospitalItem> pageList(PageTable<HospitalItem> pageTable) {
        QueryWrapper<HospitalItem> userQw = new QueryWrapper<>();
        if (pageTable.getParam() != null) {
            userQw.lambda();
        }
        Page<HospitalItem> page = super.page(pageTable.getPage(), userQw);
        return page;
    }

    @Override
    public List<HospitalItem> getHospitalItemListByNameOrType(HospitalItem item) {
        LambdaQueryWrapper<HospitalItem> itemLqw = new LambdaQueryWrapper<>();
        // 医院ID不能为空
        itemLqw.eq(HospitalItem::getHospitalId, item.getHospitalId())
                // 项目名称
                .like(StringUtils.hasText(item.getItemName())
                        & !item.getItemName().isEmpty(), HospitalItem::getItemName, item.getItemName())
                // 项目类型
                .like(StringUtils.hasText(item.getItemType())
                        & !item.getItemType().isEmpty(), HospitalItem::getItemType, item.getItemType());
        return list(itemLqw);
    }
}
